package com.mvc4g.example.mockup.client.view.views;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Event;
import com.mvc4g.example.mockup.client.Session;

public class WelcomeView extends AbstractView {
	
	private String login = null;
	
	private Label body = null;

	@Override
	protected Widget createWidget() {
		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		body = new Label();
		mainPanel.add(body);
		
		Button showEmails = new Button("See emails");
		showEmails.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				Event e = new Event(GET_EMAILS, login);				
				controller.handleEvent(e);				
			}
			
		});
		
		Button about = new Button("Go to about page");
		about.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				Event e = new Event(GO_TO_ABOUT_PAGE, null);				
				controller.handleEvent(e);				
			}
			
		});
		
		mainPanel.add(showEmails);
		mainPanel.add(about);
		
		return mainPanel;
	}

	@Override
	public void init() {
		login = (String) Session.getAttribute(LOGIN);
		body.setText("Welcome " + login);
	}

}
